<?php
$this->breadcrumbs=array(
		'access',
		'permission',
	);
?>
<div class="admin_table">
<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'index-id',
        'action' => Yii::app()->createUrl('admin/permission/index/id/'.$_POST['role']),  //<- your form action here 
		  
)); ?>


<?php  
//echo '<pre>';print_r($arrRoleList);exit;
//echo Chtml::dropDownList('role','',$arrRoleList); 
echo CHtml::dropDownList('role',$role, $arrRoleList,array('prompt'=>'Select Role','onchange'=>'this.form.submit();'));
?>

<?php $this->endWidget(); ?>



<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'form-id',
        'action' => Yii::app()->createUrl('admin/permission/index'),  //<- your form action here   
		'htmlOptions'=>array('name'=>'myform'),
)); ?>

<?php echo CHtml::beginForm(); ?>

<?php $count = 0;

if($role && $role!='')
{
?>
<table id="permission">
<tr><th>Group</th><th>View <!--<input type='checkbox' id ="key_1" name='checkview' onClick='swapCheck(1)'> --> </th><th>Update <!--  <input type='checkbox' id="key_2" name='checkall' onClick='swapCheck(2)'>--></th></tr>
<?php foreach($arrGroupList as $i=>$item): ?>
<tr>
<td><?php echo $item; ?></td>
<td id="view"><input id ="<?php echo $i.'_view'; ?>"  type="checkbox" name="view[<?php echo $i; ?>]" <?php if(isset($arrView[$i]) && $arrView[$i] == 'yes'){ echo 'value="yes" checked="checked"';  }else{ echo 'value="no"';}?> onclick='setCheckboxValue("<?php echo $i.'_view'; ?>");' ></td>
<td id="update"><input id="<?php echo $i.'_update'; ?>" type="checkbox" name="update[<?php echo $i; ?>]" <?php if(isset($arrUpdate[$i]) && $arrUpdate[$i] == 'yes'){ echo 'value="yes" checked="checked"';  }else{ echo 'value="no"';}?>  onclick='setCheckboxValue("<?php echo $i.'_update'; ?>");'></td>
</tr>
<?php $count++; endforeach; ?>
</table>
<?php echo CHtml::submitButton('Save'); ?>
<input  type="hidden" name="role_id" value="<?php echo $role ?>"> 
<!--  <b>Check All:-</b> <input type='checkbox' name='checkall' onclick='checkedAll();'> -->
<?php echo CHtml::endForm(); }  ?>
<?php $this->endWidget(); ?>
</div><!-- admin_table -->



 <script language='JavaScript'>
      checked = false;
      function checkedAll () {
        if (checked == false){checked = true;} else{checked = false; }//window.location.reload();
	for (var i = 0; i < document.getElementById('form-id').elements.length; i++) {
	  document.getElementById('form-id').elements[i].checked = checked;
	}
      }


      function setCheckboxValue(value) {

  	  if(document.getElementById(value).checked == true)
  		document.getElementById(value).value="yes";
  	  else
  		document.getElementById(value).value="no";

        }

    	    	 function swapCheck(checkBox)
    	    	 {
    	    	     if (checkBox)
    	    	     {
    	    	     	chk = document.myform.elements;
    	    	     	//alert(chk);
    	    	     	//alert("object>>>  "+document.getElementById("key_"+checkBox).checked);
    	    	         if(document.getElementById("key_"+checkBox).checked==true)
    	    	         {   
    	    	     		for (i = 0; i < chk.length; i++)
    	    	     		{
        	    	     		//alert(chk[i].getAttribute('id'));
    	    	     			if(chk[i].getAttribute('groupkey')==checkBox)
    	    	     	    	{
    	    	     				chk[i].checked=true;
    	    	     			}
    	    	     		}
    	    	         }
    	    	         else
    	    	         { //alert(">>>>");
    	    	        	 //var sURL = unescape(window.location.pathname);
    	    	        	 //window.location.replace( sURL );
    	    	        	 //window.location.reload();
    	    	         	/*for (i = 0; i < chk.length; i++)
    	    	     		{ //alert("VVVVV");
    	    	     			if(chk[i].getAttribute('groupkey')==checkBox)
    	    	     	    	{
    	    	     				chk[i].checked=false;
    	    	     			}
    	    	     		}*/
    	    	         }	              
    	    	     }
    	    	 }    	    	      
   </script>

